﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace AutoLoL.Entities
{
    public class MasteryBuild : INotifyPropertyChanged
    {
        private const int MAXIMUM_POINTS = 30;

        public MasteryTree[] MasteryTrees { get; set; }

        public SummonerSpell[] ImprovedSummonerSpells { get; set; }

        public int PointsUsed { get { return MasteryTrees.Sum(c => c.TotalUsedPoints); } }

        public int PointsAvailable { get { return MAXIMUM_POINTS - PointsUsed; } }

        public IEnumerable<MasteryValue> Masteries
        {
            get { return MasteryTrees.SelectMany(masteryTree => masteryTree.MasteryValues); }
        }

        public override string ToString()
        {
            string result = "";

            foreach (MasteryTree masteryTree in MasteryTrees)
            {
                foreach (MasteryValue mastery in masteryTree.MasteryValues)
                {
                    result += mastery.CurrentRank;
                }
            }

            return result;
        }

        public void UpdateBindings()
        {
            OnPropertyChanged("PointsUsed");
            OnPropertyChanged("PointsAvailable");
            OnPropertyChanged("ImprovedSummonerSpells");
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
